package com.aglhz.nature.adapter;

import java.util.List;


import com.aglhz.nature.R;
import com.aglhz.nature.ListView.MyGridView;
import com.aglhz.nature.modle.item.AroundData;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.content.Intent;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class AroundAdapter extends BaseAdapter{
	public List<AroundData>mData;
    public Context context; 
    private AroundGridViewAdapter adapter;
    

	public AroundAdapter(List<AroundData> mData, Context context) {
		super();
		this.mData = mData;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int  position, View convertView, ViewGroup arg2) {
		 ViewHolder viewHolder; 
			if(null==convertView){			
				  convertView = LayoutInflater.from(context).inflate(R.layout.item_around_listview, null); 
				  viewHolder = new ViewHolder();
				  viewHolder.around_shopImage = (ImageView) convertView.findViewById(R.id.around_shopImage); 
				  viewHolder.around_shopName = (TextView) convertView.findViewById(R.id.around_shopName); 
				  viewHolder.around_gridview = (MyGridView) convertView.findViewById(R.id.around_gridview); 
				  
				  convertView.setTag(viewHolder); 
			}else{
				viewHolder = (ViewHolder) convertView.getTag(); 
			}
//			//设置图片
//			
//				  String imgUrl = mData.get(position).g;
//				//picasso加载网络图片
//				   Picasso.with(context)  
//				   .load(imgUrl)  	    	               
//				   .into(viewHolder.around_shopImage) ;
			adapter=new AroundGridViewAdapter(mData.get(position).getLstData(), context);	  
			 viewHolder.around_gridview.setAdapter(adapter);	   
			//设置文字
			viewHolder.around_shopName.setText(mData.get(position).getShopName());
//			
//			int screenWidth = getScreenWidth();
//			GridView.LayoutParams p=new GridView.LayoutParams(screenWidth,screenWidth);
//			convertView.setLayoutParams(p);

			return convertView;
		}
		class ViewHolder 
		{  
		    public ImageView around_shopImage;
		    public TextView around_shopName;
		    public GridView around_gridview;
		} 
		
		/**
		 * 获取屏幕宽度
		 * 
		 * @return
		 */
		protected int getScreenWidth() {
			WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
			Display display = wm.getDefaultDisplay();
			return display.getWidth();
		}

}
